package vip.huhailong.rabbitmqdemo.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Huhailong
 * @Description 直连型交换机
 * @Date 2021/11/18.
 */
@Configuration
public class DirectRabbitConfig {

    /**
     * 队列名为 TestDirectQueue
     * @return 返回队列
     */
    @Bean
    public Queue TestDirectQueue(){
        return new Queue("TestDirectQueue");
    }

    /**
     * Direct 交换机
     * 起名为：TestDirectExchange
     * @return Direct Exchange
     */
    @Bean
    DirectExchange TestDirectExchange(){
        return new DirectExchange("TestDirectExchange");
    }

    /**
     * 绑定 将队列和交换机绑定，并设置用于匹配键：TestDirectRouting
     * @return Binding
     */
    @Bean
    Binding bindingDirect() {
        return BindingBuilder.bind(TestDirectQueue()).to(TestDirectExchange()).with("TestDirectRouting");
    }

    @Bean
    DirectExchange lonelyDirectExchange(){
        return new DirectExchange("lonelyDirectExchange");
    }
}
